import 'dart:convert';
import 'dart:ui';

import 'package:flustars/flustars.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_theme/styles.dart';
import 'package:flutter_theme/theme.dart';
import 'package:flutter_theme/theme_utils.dart';

import 'colors.dart';
import 'constant.dart';

class ThemeProvider extends ChangeNotifier {
  String theme = "";

  void setTheme(String themeMode) {
    this.theme = themeMode;
    WXTheme().setThemeType(themeMode);
    notifyListeners();
  }

  ThemeMode getThemeMode(BuildContext context) {
    print(
        "ThemeMode=======>${WXTheme().themeType}=====>$theme======>${ThemeUtils.isDark(context)}====>${window.platformBrightness}");
    ThemeMode themeMode;
//    String spTheme = SpUtil.getString(Constant.themeModel, defValue: "");
//    if (theme == null || theme != spTheme) {
//      theme = SpUtil.getString(Constant.themeModel, defValue: "system");
//    }
    theme = WXTheme().themeType;
    print("theme======>${WXTheme().themeType}");
    WXTheme().setFollowSystem(false);
    switch (theme) {
      case "system":
        WXTheme().setFollowSystem(true);
        if (window.platformBrightness == Brightness.light) {
          WXTheme().setThemeType("light");
        } else {
          WXTheme().setThemeType("dark");
        }
        themeMode = ThemeMode.system;
        break;
      case "dark":
        themeMode = ThemeMode.dark;
        WXTheme().setThemeType("dark");
        break;
      default:
        themeMode = ThemeMode.light;
        WXTheme().setThemeType(theme);
        break;
    }
    return themeMode;
  }

  //Dark和Light模式
  ThemeData getTheme({bool isDarkMode = false}) {
    return ThemeData(
//      errorColor: isDarkMode ? Colours.dark_red : Colours.red,
      brightness: isDarkMode ? Brightness.dark : Brightness.light,
//      primaryColor: isDarkMode ? Colours.dark_app_main : Colours.app_main,
//      accentColor: isDarkMode ? Colours.dark_app_main : Colours.app_main,
//      indicatorColor: isDarkMode ? Colours.dark_app_main : Colours.app_main,
//      scaffoldBackgroundColor:
//          isDarkMode ? Colours.dark_bg_color : Colors.white,
//        canvasColor: isDarkMode ? Colours.dark_material_bg : Colors.white,
//        textSelectionColor: Colours.app_main.withAlpha(70),
//        textSelectionHandleColor: Colours.app_main,
//        textTheme: TextTheme(
//          subtitle1: isDarkMode ? TextStyles.textDark : TextStyles.text,
//          bodyText2: isDarkMode ? TextStyles.textDark : TextStyles.text,
//          subtitle2:
//          isDarkMode ? TextStyles.textDarkGray12 : TextStyles.textGray12,
//        ),
//        inputDecorationTheme: InputDecorationTheme(
//            hintStyle:
//            isDarkMode ? TextStyles.textHint14 : TextStyles.textDarkGray14),
//        appBarTheme: AppBarTheme(
//          //  color: isDarkMode ? Colours.dark_bg_color : Colors.white,
//          textTheme: TextTheme(
//            headline6: TextStyle(
//                color: isDarkMode ? Colors.white : Colors.white, fontSize: 18),
//            bodyText1:
//            TextStyle(color: isDarkMode ? Colors.white : Colors.black),
//            bodyText2:
//            TextStyle(color: isDarkMode ? Colors.white : Colors.black),
//          ),
//          iconTheme:
//          IconThemeData(color: isDarkMode ? Colors.white : Colors.white),
//          color: isDarkMode ? Colors.grey[800] : Colours.app_main,
////          brightness: isDarkMode ? Brightness.dark : Brightness.dark
//        ),
//        dividerTheme: DividerThemeData(
//          color: isDarkMode ? Colors.grey[400] : Colors.grey[200],
//        ),
//        cupertinoOverrideTheme: CupertinoThemeData(
//            brightness: isDarkMode ? Brightness.dark : Brightness.light),
//        cardColor: isDarkMode ? Colors.grey[850] : Colors.white,
//        cursorColor: isDarkMode ? Colors.white : Colors.grey[400]
    );
  }
}
